package com.beta.admin.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.beta.admin.support.web.BaseController;
import com.beta.common.web.ContentType;
import com.beta.dto.admin.TransactionDto;
import com.beta.service.ITransactionsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * Created by lichao on 2017/1/24.
 */
@RestController
@RequestMapping(value = RequestMappingConstants.MAPPING_PREFIX + "/transactions")
public class TransactionController extends BaseController {
    @Autowired
    private ITransactionsService transactionsService;
    @GetMapping(value = "/{resourceId}",produces = ContentType.JSON)
    public Object getTransaction(@PathVariable("resourceId")Integer resourceId){
        return transactionsService.getTransactions(resourceId);
    }
    @RequiresPermissions("transaction:list")
    @GetMapping(value = "",produces = ContentType.JSON)
    public Object getTransactions(@RequestParam("code")String code, @RequestParam("amountBegin")BigDecimal amountBegin,
                                  @RequestParam("amountEnd")BigDecimal amountEnd, @RequestParam("username")String username){

        Page<TransactionDto> transactions = transactionsService.getTransactions(getMybatisPage(),code,amountBegin,amountEnd,username);
        return pageData(transactions);
    }
    @RequiresPermissions("transaction:view")
    @GetMapping(value="/detail/{id}",produces = ContentType.JSON)
    public Object getTransactionDetail(@PathVariable("id")Integer id){
        return transactionsService.getTransactionDetail(id);
    }
}
